#define DEUBG
#include <cstdio>

using namespace std;

const int maxn=100000, mods=998244353;

class Tree {
public:
  int n, m, ind[maxn+1], link[2*maxn+1], to[2*maxn+1], dep[maxn+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void build(int o, int fa) {
    dep[o] = dep[fa]+1;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	build(to[i], o);
      }
    }
  }
};

long long qpower(long long a, int n) {
  long long s=1;
  for (; n>1; n/=2) {
    if (n%2) {
      s = s*a%mods;
    }
    a = a*a%mods;
  }
  return s*a%mods;
}

int main() {
  freopen("treasure.in", "r", stdin);
  freopen("treasure.out", "w", stdout);

  static Tree tree;
  static int a[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
    tree.addSide(a[i], i);
  }

  for (int i=1; i<=n; i++) {
    if (a[i]==-1) {
      tree.build(i, 0);
    }
  }

  long long fact[maxn+1];
  fact[0] = 1;
  for (int i=1; i<=n; i++) {
    fact[i] = (fact[i-1]*i)%mods;
  }
  fact[0] = 0;

  long long ans=0;
  for (int i=1; i<=n; i++) {
    ans = (ans+qpower(fact[tree.dep[i]], mods-2))%mods;
  }
  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
